// import path from "path";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import vueJsx from "@vitejs/plugin-vue-jsx";
import Components from "unplugin-vue-components/vite";
import { NaiveUiResolver } from "unplugin-vue-components/resolvers";
import bundleAnalyzer from "rollup-plugin-bundle-analyzer";
import viteCompression from "vite-plugin-compression";
import { svgTagView } from "./src/plugins/svg-tag-view";
import versionInfo from "./src/global/version";

function changeVersion() {
  versionInfo.version = Math.floor(Math.random() * 100000).toString();
}
changeVersion();

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueJsx(),
    Components({
      resolvers: [NaiveUiResolver()],
    }),
    viteCompression({
      verbose: true,
      disable: false,
      threshold: 10240,
      algorithm: "gzip",
      ext: ".gz",
    }),
    bundleAnalyzer({}),
    svgTagView("./src/assets/icons/svg"),
  ],
  resolve: {
    alias: [
      {
        find: "@",
        replacement: path.resolve(__dirname, "src"),
      },
    ],
  },
  server: {
    port: 8008,
  },
});
